<template>
  <div>
    <el-card class="box-card">
      <template #header>
        <span>角色权限配置</span>
      </template>
      <div v-hasPermission="'qm:auth:role:do'" class="m-b-10">
        <m-all-btn :button-list="overallBtn" />
      </div>
      <m-table
        v-loading="dataGrid.loading"
        :height="dataGrid.height"
        :list="dataGrid.data"
        :columns="dataGrid.columns"
        :pagination="dataGrid.pagination"
        @handle-pagination-change="dataGrid.changePagination"
        @select-change="dataGrid.selectChange"
      >
        <template #action="scope">
          <m-all-btn :button-list="dataGrid.btnList" :scope="scope" />
        </template>
      </m-table>

    </el-card>

    <!-- 配置角色及权限 -->
    <op-perm
      :role-id="permDialog.roleId"
      :op-perm-show.sync="permDialog.show"
      @search="search"
    />

    <!-- 新增编辑 -->
    <m-modal-form
      width="319px"
      :title="editForm.formType !== 'add' ? editForm.title[0] :editForm.title[1]"
      :form-attrs="editForm.formAttrs"
      :visible.sync="editForm.visible"
      :form-type="editForm.formType"
      :options="editForm.options"
      @save="save"
    />
  </div>
</template>
<script>

// 混入 minxin 文件夹下面所有的js文件
const files = require.context("./mixins", false, /\.js$/);
const minxins = [];
files.keys().forEach(key => {
  minxins.push(files(key).default || files(key));
});

import opPerm from "./components/opPerm.vue";

import { getRoleList } from "@/api/auth";

export default {
  name: "AtteException",
  components: {
    opPerm
  },
  mixins: [...minxins],
  data() {
    return {
      permDialog: {
        show: false,
        row: null,
        // 编辑时的ID
        roleId: -1
      },
      multipleSelection: []
    };
  },
  created() {
    this.search();
  },
  methods: {
    search() {
      const para = {
        sysName: "QM"
      };
      getRoleList(para).then(res => {
        this.dataGrid.data = res.map(item => {
          item.userIds = [];
          item.names = [];
          const userList = item.userList || [];

          for (let i = 0; i < userList.length; i++) {
            const { id, name } = userList[i] || {};
            item.userIds.push(id);
            item.names.push(name);
          }
          if (item.names.length) item.names = item.names.join(",");
          return item;
        });
      });
    }
  }
};
</script>

